package com.assistant.util;
import org.springframework.context.ApplicationContext;
import java.util.Objects;

public class SpringContextUtil {
    private static ApplicationContext applicationContext;

    public SpringContextUtil() {
    }

    public static ApplicationContext getApplicationContext() {
        return applicationContext;
    }

    public static void setApplicationContext(ApplicationContext context) {
        applicationContext = context;
    }

    public static Object getBean(String name) {
        Objects.requireNonNull(applicationContext);
        return getApplicationContext().getBean(name);
    }

    public static <T> T getBean(Class<T> clazz) {
        Objects.requireNonNull(applicationContext);
        return getApplicationContext().getBean(clazz);
    }

    public static <T> T getBean(String name, Class<T> clazz) {
        Objects.requireNonNull(applicationContext);
        return getApplicationContext().getBean(name, clazz);
    }
}